/**
 * Copyright  2025, Hai Yue Xing He Technology Co., Ltd
 * 
 * @author          ZHAO LIMIN
 * @version         1.0.1
 * @since           2025-04
 * HYXHGeoTools.ts  标准类，用于记录矢量图将cc.object 进行矢量化用于检测碰撞，相叠等。
 */
import { Vec2, Vec3 } from "cc";
import {ICartesian} from "./Cartesian";   
import { Check } from "./Check";

export class HYXHGeoTools {
    /**
     * 计算两点之间的距离
     * @param start_p       起始点
     * @param end_p         结束点 
     * @returns             两点之间的距离
     */
    public static calculateDistanceVec2(start_p: Vec2, end_p : Vec2): number {
        return Math.sqrt(Math.pow(start_p.x - end_p.x, 2) + Math.pow(start_p.y - end_p.y, 2));
    }
    /**
     * 计算两点之间的距离(3D)
     * @param start_p       起始点
     * @param end_p         结束点
     * @returns             两点之间的距离
     */
    public static calculateDistanceVec3(start_p: Vec3, end_p : Vec3): number {
        return Math.sqrt(Math.pow(start_p.x - end_p.x, 2) + Math.pow(start_p.y - end_p.y, 2) + Math.pow(start_p.z - end_p.z, 2));
    }
    /**
     * 计算两点之间的距离
     * @param start_p       起始点
     * @param end_p         结束点 
     * @returns             两点之间的距离
     */
    public static calculateDistancePoint(start_p: ICartesian, end_p : ICartesian): number {
        return Math.sqrt(Math.pow(start_p.x - end_p.x, 2) + Math.pow(start_p.y - end_p.y, 2));
    }
    /**
     * 获得中线点
     * @param start 
     * @param end 
     * @returns 
     */
    public static getCenterOfTwoPoints(start: ICartesian, end : ICartesian): ICartesian { 
        Check.defined("start", start);
        Check.defined("end", end);
        return {x: (start.x + end.x) / 2, y: (start.y + end.y) / 2, z: (start.z + end.z) / 2};
    }

}